package com.lzm.ydpt.utils;

import android.os.CountDownTimer;
import android.widget.TextView;

import com.byt.framlib.commonutils.TimeUtil;


/**
 * 倒计时器
 */
public class WinCutDown extends CountDownTimer {
    private String mEndStr;
    private TextView mTextView;
    private FinishLister mFinishLister;

    /**
     * 1分钟
     *
     * @param btn    倒计时按钮
     * @param endStr 计时结束时显示胡字符rid
     */
    public WinCutDown(TextView btn, long TIME_COUNT, String endStr, FinishLister finishLister) {
        super(TIME_COUNT, 1000);
        this.mTextView = btn;
        this.mEndStr = endStr;
        this.mFinishLister = finishLister;
    }


    // 计时完毕时触发
    @Override
    public void onFinish() {
        mTextView.setText(mEndStr);
        mTextView.setEnabled(true);
        mFinishLister.listerFinishCut();
    }

    public void onCancel() {
        cancel();
    }

    // 计时过程显示
    @Override
    public void onTick(long millisUntilFinished) {
        mTextView.setText(TimeUtil.formatCaiPiaoCutTime(millisUntilFinished));
    }

    public interface FinishLister {
        void listerFinishCut();
    }
}